// zh_gjw/pages/reputation/reputation.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
		var that=this
		that.list()
		that.rlist()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

	}, 
	list: function (e) {
		var that = this
		getApp().util.request({
			'url': 'entry/wxapp/reputation',
			'cachetime': '0',
			success: function (res) {
				if (res.data.code == 200) {
					that.setData({
						list: res.data.res
					})
				}
			}
		});
	},
	rlist: function (e) {
		var that=this
		getApp().util.request({
			'url': 'entry/wxapp/reputationrecord',
			'cachetime': '0',
			data: { admin: wx.getStorageSync('adminlogin') },
			success: function (res) {
				console.log(res)
				if (res.data.code == 200) {
					that.setData({
						rlist: res.data.res
					})
				}
			}
		});
	},
	money: function (e) {
		var that=this
		getApp().util.request({
			url: 'entry/wxapp/reputationpay',
			data: {
				admin: wx.getStorageSync('adminlogin'),
				grade: e.currentTarget.dataset.grade, 
				money: e.currentTarget.dataset.money
			},
			success: function (res) {
				wx.requestPayment({
					'timeStamp': res.data.return.timeStamp,
					'nonceStr': res.data.return.nonceStr,
					'package': res.data.return.package,
					'signType': 'MD5',
					'paySign': res.data.return.paySign,
					'success': function (ress) {
						getApp().util.request({
							url: 'entry/wxapp/reputationpaysuccess',
							data: {
								id: res.data.res_id
							},
							success: function (resok) {
								that.setData({
									list: [],
									rlist: [],
								})
								that.list()
								that.rlist()
							}
						})

					},
					'fail': function (res) {
						wx.showToast({
							title: '支付失败',
							icon: "loading",
						})
					},

				})

			}

		})
	},
	qmoney: function (e) {
		var that=this
		var start
		var now
		var end
		start = Date.parse(new Date(e.currentTarget.dataset.time))/1000
		now = Date.parse(new Date())/1000
		end = start+86400*365
		console.log(start)
		console.log(now)
		console.log(end)
		if(now<end){
			wx.showModal({
				title: '提示',
				content: '一年之期未到',
			})
		}else{
			getApp().util.request({
				url: 'entry/wxapp/reputationtx',
				data: {
					id: e.currentTarget.dataset.id
				},
				success: function (res) {
					console.log(res)
					return
					if(res.data.code==200){
						wx.showToast({
							title: '提现成功',
							duration: 3000,
						})
						setTimeout(function () {
							that.setData({
								list: [],
								rlist: [],
							})
							that.list()
							that.rlist()
						}, 3000)
					}
				}
			})
		}
	}
})